package com.lou.util;

import java.util.HashMap;
import java.util.Map;

import lombok.Data;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/** 
 * @author : ljl
 * @date 创建时间：2018年9月13日 上午10:55:14 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@Configuration
@ConfigurationProperties(prefix="test-properties")
@PropertySource("classpath:application-dev.yml")
@Data
public class ReadProperties {
	
	private String activePeople = "lou";
	//必须与配置文件的目录名一样
	private Map<String, People> peoples = new HashMap<>();
	@Data
//	最好加上校验，具体的校验格式在字段上加上注解
//	@Validated
	public static class People{
		private String name;
		private String sex;
	}
	public People getActivePeople() {
		System.out.println(peoples.get(activePeople));
		return peoples != null ? peoples.get(activePeople) : null;
	}

	public String getName() {
		People activePeople = getActivePeople();
		return activePeople != null ? activePeople.getName() : null;
	}
	public String getSex() {
		People activePeople = getActivePeople();
		return activePeople != null ? activePeople.getSex() : null;
	}
}
